﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using System.Resources;

using Epic.Core;

namespace Epic.ComponentServices
{
    [AttributeUsage(AttributeTargets.All)]
    public class LocalizedCategoryAttribute : CategoryAttribute
    {
#pragma warning disable 1591

        public ResourceManager ResourceManager { get; private set; }
        public CultureInfo Culture { get; set; }

        #region Constructors

        protected LocalizedCategoryAttribute(ResourceManager resourceManager, string key)
            : base(key)
        {
            if (resourceManager == null)
                throw NewException.ArgumentNull(() => resourceManager);

            this.ResourceManager = resourceManager;
        }

        #endregion

        protected virtual string GetResourceKey(string category)
        {
            return "PropertyCategory" + category;
        }

        protected override string GetLocalizedString(string value)
        {
            return ResourceManager.GetString(GetResourceKey(value), Culture) ?? base.GetLocalizedString(value);
        }
    }
}
